package com.gui.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gui.hospital.mapper.HospitalDepartmentMapper;
import com.gui.hospital.model.HospitalDepartment;
import com.gui.hospital.service.HospitalDepartmentService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author:刘舒佳
 * Date:2024/8/23
 */
@Service
@AllArgsConstructor
public class HospitalDepartmentServiceImpl extends ServiceImpl<HospitalDepartmentMapper, HospitalDepartment> implements HospitalDepartmentService {
   private final HospitalDepartmentMapper hospitalDepartmentMapper;

   /**
    * 通过科室名称查询科室
    * @param name
    * @return
    */
   @Override
   public List<HospitalDepartment> getDepartmentByName(String name) {
      QueryWrapper<HospitalDepartment> hospitalDepartmentQueryWrapper = new QueryWrapper<>();
      hospitalDepartmentQueryWrapper.lambda().like(name!=null&&!"".equals(name),HospitalDepartment::getName, name);
      List<HospitalDepartment> hospitalDepartments = hospitalDepartmentMapper.selectList(hospitalDepartmentQueryWrapper);
      return hospitalDepartments;
   }

   /**
    * 根据上级科室id查询科室
    * @param pid
    * @return
    */
   @Override
   public List<HospitalDepartment> getDepartmentByPid(Integer pid) {
      QueryWrapper<HospitalDepartment> hospitalDepartmentQueryWrapper = new QueryWrapper<>();
      hospitalDepartmentQueryWrapper.lambda().eq(pid!=null,HospitalDepartment::getPid, pid);
      List<HospitalDepartment> hospitalDepartments = hospitalDepartmentMapper.selectList(hospitalDepartmentQueryWrapper);
      return hospitalDepartments;
   }

   @Override
   public Page<HospitalDepartment> pageList(Integer page, Integer size, HospitalDepartment hospitalDepartment, HospitalDepartment hospitalDepartment1) {
      Page<HospitalDepartment> hospitalDepartmentPage = new Page<>(page,size);
      QueryWrapper<HospitalDepartment> hospitalDepartmentQueryWrapper = new QueryWrapper<>();
      hospitalDepartmentQueryWrapper.lambda().like(hospitalDepartment.getName()!=null&&!"".equals(hospitalDepartment.getName()),HospitalDepartment::getName, hospitalDepartment.getName());
      hospitalDepartmentQueryWrapper.lambda().eq(hospitalDepartment.getPid()!=null,HospitalDepartment::getPid, hospitalDepartment.getPid());
      Page<HospitalDepartment> hospitalDepartmentPage1 = hospitalDepartmentMapper.selectPage(hospitalDepartmentPage, hospitalDepartmentQueryWrapper);
      return hospitalDepartmentPage1;
   }
}
